/******************************************************************************
** $Id: dc_rammgr_api.h,v 1.1.1.1 2009-02-13 22:36:43 beliloi Exp $
**                 Proprietary and Confidential Information                  **
**                                                                           **
**                 Copyright (c) SigmaTel, Inc. Unpublished                  **
**                                                                           **
** This source code and the algorithms implemented therein constitute        **
** confidential information and may compromise trade secrets of SigmaTel,    **
** Inc. or its associates, and any unauthorized use thereof is prohibited.   **
**                                                                           **
******************************************************************************/

#ifndef DC_RAMMGR_API_H
#define DC_RAMMGR_API_H

typedef enum 
{
    DC_BUFFER_UNAVAILABLE = 0,
    DC_BUFFER_AVAILABLE,
    DC_BUFFER_NO_MEMORY
} DC_RAMMGR_BUFFER_STATUS;

#define DC_RAMMGR_MAX_NAME_LEN 32

/*******************************************************************
 *
 * DC_RAMMGR_BUFFER_ENTRY
 *   The application must allocate one of these structures for
 *   each RAM buffer.  The data should be considered read only.
 *
 */
typedef struct DC_RAMMGR_BUFFER_ENTRY_STRUCT
{
    char name[DC_RAMMGR_MAX_NAME_LEN];
    UINT32 bufferId;
    UINT32 alignment;
    DC_RAMMGR_BUFFER_STATUS status;
    UINT32 address;
    UINT32 length;
    DC_RETURN_CODE (*bufferCallback)(struct DC_RAMMGR_BUFFER_ENTRY_STRUCT * entry);
    struct DC_RAMMGR_BUFFER_ENTRY_STRUCT * next;
} DC_RAMMGR_BUFFER_ENTRY;

typedef enum 
{
    DC_TYPE_PSB = 0,
    DC_TYPE_TSB
} DC_RAMMGR_BUFFER_TYPE;

/*******************************************************************
 *
 * DC_RAMMGR_RAMMAP_STATE
 *   The application must allocate one of these structures for
 *   each RAM state.  Although the members are accessible, they
 *   should not be modified except through the API.
 *
 */
typedef struct DC_RAMMGR_RAMMAP_STATE_STRUCT
{
    char name[DC_RAMMGR_MAX_NAME_LEN];
    UINT32 stateId;

    UINT32 tsbAreaStart;
    UINT32 tsbAreaLen;

    DC_RAMMGR_BUFFER_ENTRY *tsbList;

    struct DC_RAMMGR_RAMMAP_STATE_STRUCT * next;

} DC_RAMMGR_RAMMAP_STATE;

/*******************************************************************
 *
 * DC_RAMMGR_MEMORY_STATUS
 *   This structure is provided to the memoryChangeCallback when
 *   changes occur in the memory status.
 *
 */
typedef struct
{
    UINT32 start;
    UINT32 total;
    UINT32 currentStateMemoryUsed;
    UINT32 nextStateMemoryUsed;
    UINT32 maxMemoryUsed;
    UINT32 valid;
} DC_RAMMGR_MEMORY_STATUS;

// RAM Manager Interface prototypes
//
DC_RETURN_CODE dc_rammgr_debug(void * dataPtr, UINT32 request);
DC_RETURN_CODE dc_rammgr_init(void);
DC_RETURN_CODE dc_rammgr_rammap_state_create(DC_RAMMGR_RAMMAP_STATE * state, 
                                            UINT32 stateId, 
                                            char * name);
DC_RETURN_CODE dc_rammgr_buffer_request(DC_RAMMGR_BUFFER_ENTRY * ramBuf, 
                                       char * bufferName,
                                       UINT32 bufferId, 
                                       UINT32 size, 
                                       UINT32 alignment, 
                                       DC_RAMMGR_BUFFER_TYPE type, 
                                       UINT32 stateId,
                                       DC_RETURN_CODE (*bufferCallback) 
                                            (struct DC_RAMMGR_BUFFER_ENTRY_STRUCT * entry) );
DC_RETURN_CODE dc_rammgr_start(UINT32 ramStart, 
                              UINT32 ramSize, 
                              UINT32 initialRammgrStateId,
                              DC_RETURN_CODE (*memoryChangeCallback)
                                  (DC_RAMMGR_MEMORY_STATUS * status));
DC_RETURN_CODE dc_rammgr_rammap_state_activate(UINT32 stateId);

void dc__rammgr_log(char *when);

DC_RETURN_CODE dc_rammgr_export(void);

#endif // DC_RAMMGR_API_H
